﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using DBUtility;
using IDAL;
using Model;
using System;

namespace DAL
{
    public class TestItem_CPK:ITestItem_CPK
    {
        #region 静态变量定义部分
        private const string PARM_TESTITEM_MONTHTIME = "@MonthTime";
        private const string PARM_TESTITEM_WEEKTIME = "@WeekTime";
        private const string PARM_TESTITEM_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_TESTITEM_STARTTIME = "@starttime";
        private const string PARM_TESTITEM_STOPTIME = "@stoptime";
        #endregion

        #region 数据检索部分
        public IList<CPKInfo> GetCPK4(string spname, string productTypeID, DateTime starttime, DateTime stoptime)
        {
            IList<CPKInfo> t_qs = new List<CPKInfo>();
            SqlParameter[] testParms = GetParameters();
            testParms[0].Value = productTypeID;
            testParms[1].Value = starttime;
            testParms[2].Value = stoptime;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    CPKInfo t_q = new CPKInfo(rdr.GetValue(0).ToString(), rdr.GetInt32(1), rdr.GetDouble(2), rdr.GetDouble(3));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<CPKInfo> GetCPKbyPID_DT(string productTypeID, DateTime starttime, DateTime stoptime)
        {
            return GetCPK4("TestItem_CPKbyPID_DT", productTypeID, starttime, stoptime);
        }

//--------------------------------------------------------------------------------------------------------------------------

        public IList<CPKInfo> GetCPK3(string spname,string yearTime, string productTypeID)
        {
            IList<CPKInfo> t_qs = new List<CPKInfo>();
            SqlParameter[] testParms = GetParameters2();
            testParms[0].Value = yearTime;
            testParms[1].Value = productTypeID;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    CPKInfo t_q = new CPKInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2), rdr.GetDouble(3), rdr.GetDouble(4));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<CPKInfo> GetCPK3_1(string spname, string yearTime, string productTypeID)
        {
            IList<CPKInfo> t_qs = new List<CPKInfo>();
            SqlParameter[] testParms = GetParameters3();
            testParms[0].Value = yearTime;
            testParms[1].Value = productTypeID;

            using (SqlDataReader rdr = sqlHelper.ExecuteReader(sqlHelper.ConnectionStringLocalTransaction, CommandType.StoredProcedure, spname, testParms))
            {
                while (rdr.Read())
                {
                    CPKInfo t_q = new CPKInfo(rdr.GetValue(0).ToString(), rdr.GetValue(1).ToString(), rdr.GetInt32(2), rdr.GetDouble(3), rdr.GetDouble(4));
                    t_qs.Add(t_q);
                }
            }
            return t_qs;
        }

        public IList<CPKInfo> GetCPKbyPID_Month(string yearTime, string productTypeID)
        {
            return GetCPK3("TestItem_CPKbyPID_Month", yearTime, productTypeID);
        }

        public IList<CPKInfo> GetCPKbyPID_Week(string yearTime, string productTypeID)
        {
            return GetCPK3_1("TestItem_CPKbyPID_Week", yearTime, productTypeID);
        }
        #endregion

        #region 参数部分
        private static SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TESTITEM_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TESTITEM_STARTTIME, SqlDbType.DateTime, 8),
					new SqlParameter(PARM_TESTITEM_STOPTIME, SqlDbType.DateTime, 8)             
                };
            return parms;
        }

        private static SqlParameter[] GetParameters2()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TESTITEM_MONTHTIME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TESTITEM_PRODUCTTYPEID, SqlDbType.NVarChar, 50)             
                };
            return parms;
        }

        private static SqlParameter[] GetParameters3()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_TESTITEM_WEEKTIME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TESTITEM_PRODUCTTYPEID, SqlDbType.NVarChar, 50)             
                };
            return parms;
        }
        #endregion
    }
}
